import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class GridViewDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Demo()
    );
  }
}


class Demo extends StatefulWidget {
  @override
  _DemoState createState() => _DemoState();
}

class _DemoState extends State<Demo> {
  @override
  Widget build(BuildContext context) {
    ScreenUtil.instance = ScreenUtil(width: 750, height: 1334,allowFontScaling: true)..init(context);
    return Scaffold(
        appBar: AppBar(
          title: Text('测试'),
          elevation: 0,
        ),
        body: GridView.count(
          padding: const EdgeInsets.all(8.0),
          primary: false,
          mainAxisSpacing: 12.0,              // 竖向间距
          crossAxisCount: 3,                  // 横向 Item 的个数
          crossAxisSpacing: 12.0,             // 横向间距
          children: buildGridTileList(15),
        ),
    );
  }
}

String imgsrc = 'http://5b0988e595225.cdn.sohucs.com/images' +
    '/20171218/342e43903694448b91698b5ce7623314.jpeg';

List<Widget> buildGridTileList(int number) {
  List<Widget> widgetList = new List();

  for (int i = 0; i < number; i++) {
    widgetList.add(new Container(
      decoration: new BoxDecoration(
        color: Colors.white,
        image: new DecorationImage(
          image: new NetworkImage(imgsrc),
          fit: BoxFit.cover,
        ),
        shape: BoxShape.circle,
        boxShadow: <BoxShadow>[
          new BoxShadow(
            offset: new Offset(0.0, 1.0),
            blurRadius: 2.0,
            color: const Color(0xffaaaaaa),
          ),
        ],
      ),
    ));
  }
  return widgetList;
}

